home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 31 / Amiga Format CD31 (1998-09-02)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1998-10].iso / -seriously_amiga- / hardware / transadf / source / args.c next >
C/C++ Source or Header  |  1998-07-20  |  3KB  |  95 lines

  1. /* args.c - collect program arguments
  2. ** Copyright (C) 1998 Karl J. Ots
  3. ** 
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. ** 
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. ** 
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. #include <exec/types.h>
  20. #include <dos/rdargs.h>
  21. #include <clib/dos_protos.h>
  22.  
  23. #include <string.h>
  24.  
  25. #include "args.h"
  26.  
  27. const char TA_Template[] = "DRIVE/A,FILE/A,S=START/N,E=END/N,WRITE/S,VERIFY/S,\
  28. ZLIB/S,GZIP/S,PKZIP/S,NAME/K,LEVEL/N,ADD/S";
  29.  
  30. struct TA_RDArgs {
  31.   STRPTR  DRIVE;
  32.   STRPTR  FILE;
  33.   ULONG  *START;
  34.   ULONG  *END;
  35.   ULONG   WRITE;
  36.   ULONG   VERIFY;
  37.   ULONG   ZLIB;
  38.   ULONG   GZIP;
  39.   ULONG   PKZIP;
  40.   STRPTR  NAME;
  41.   ULONG  *LEVEL;
  42.   ULONG   ADD;
  43. };
  44.  
  45.  
  46. /*
  47. ** Collect the progam arguments.
  48. */
  49. struct TA_Args *getArgs (void)
  50. {
  51.   static struct TA_Args taArgs;
  52.   struct RDArgs *rdargs;
  53.   struct TA_RDArgs taRDArgs = {NULL,  NULL,  NULL,  NULL, FALSE, FALSE, 
  54.                                FALSE, FALSE, FALSE, NULL, NULL,  FALSE};
  55.   
  56.   
  57.   /* Analyse arguments */
  58.   rdargs = ReadArgs (TA_Template, (ULONG *)&taRDArgs, NULL);
  59.   if (!rdargs) return NULL;
  60.   
  61.   /* Fill in the defauts */
  62.   taArgs.Drive     = NULL;
  63.   taArgs.File      = NULL;
  64.   taArgs.Start     = 0;
  65.   taArgs.End       = 159;
  66.   taArgs.WriteDisk = FALSE;
  67.   taArgs.Verify    = FALSE;
  68.   taArgs.ZLib      = FALSE;
  69.   taArgs.GZip      = FALSE;
  70.   taArgs.PKZip     = FALSE;
  71.   taArgs.PKZAdd    = FALSE;
  72.   taArgs.OrigName  = "disk.adf";
  73.   taArgs.Level     = 6;
  74.   
  75.   /* Copy arguments into the 'real' structure if required          */
  76.   /* We'll assume that strdup() always works -- dumb but easier :) */
  77.   if (taRDArgs.DRIVE)  taArgs.Drive     = strdup (taRDArgs.DRIVE);
  78.   if (taRDArgs.FILE)   taArgs.File      = strdup (taRDArgs.FILE);
  79.   if (taRDArgs.START)  taArgs.Start     = *(taRDArgs.START) * 2;
  80.   if (taRDArgs.END)    taArgs.End       = *(taRDArgs.END) * 2 + 1;
  81.   if (taRDArgs.WRITE)  taArgs.WriteDisk = TRUE;
  82.   if (taRDArgs.VERIFY) taArgs.Verify    = TRUE;
  83.   if (taRDArgs.ZLIB)   taArgs.ZLib      = TRUE;
  84.   if (taRDArgs.GZIP)   taArgs.GZip      = TRUE;
  85.   if (taRDArgs.PKZIP)  taArgs.PKZip     = TRUE;
  86.   if (taRDArgs.ADD)    taArgs.PKZAdd    = TRUE;
  87.   if (taRDArgs.NAME)   taArgs.OrigName  = strdup (taRDArgs.NAME);
  88.   if (taRDArgs.LEVEL)  taArgs.Level     = *(taRDArgs.LEVEL);
  89.   
  90.   /* Get rid of the temporary stuff */
  91.   FreeArgs (rdargs);
  92.   
  93.   return &taArgs;
  94. }
  95.